﻿using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Xml;

namespace AvalonEditor
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            //InitializeComponent();
            //CodeEditor.Text = "public class MyClass \n{\n public void MyMethod()\n {\n Console.WriteLine(\"Hello, World!\");\n }\n }";
            //CodeEditor.FontFamily = new FontFamily("NSimSun");//  Consolas  新宋体 NSimSun
            //CodeEditor.FontSize = 13;

            ////textEdit.Completion = completion;
            //CodeEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");

            //CodeEditor.VerticalAlignment = VerticalAlignment.Stretch;
            //CodeEditor.HorizontalAlignment = HorizontalAlignment.Stretch;


            IHighlightingDefinition customHighlighting;
            using (Stream s = new FileStream("NotConvertPeps.PEPSHighlighting.xshd",FileMode.Open))
            {
                using (XmlReader reader = new XmlTextReader(s))
                {
                    customHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
                }
            }
            //要设置一个后缀名字，在这里我设置了fre
            HighlightingManager.Instance.RegisterHighlighting("Custom Highlighting", new string[] { ".fre" }, customHighlighting);

            InitializeComponent();
            //在InitializeComponent()之后使用，为txtEdit设置高亮语法
            CodeEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(".fre");
        }
    }
}
